<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.prime.com.tr/ui">

    <ui:composition >

        <p:panel id="panelIDinViewSO" header="Sales Order # #{salesOrderEntityController.selected.id}">
            <h:panelGrid columns="2">

                <h:outputText value="#{bundle.ViewSalesOrderEntityLabel_customer}"/>
                <h:outputText value="#{salesOrderEntityController.selected.customer.fullname}" title="#{bundle.ViewSalesOrderEntityTitle_customer}"/>

                <h:outputText value="Customer Executive:"/>
                <h:outputText value="#{salesOrderEntityController.selected.systemUser.fullname}"/>

                <h:outputText value="Promotion"/>
                <h:selectBooleanCheckbox id="checkbox" value="#{salesOrderEntityController.selected.promotion}" disabled="true"/>

                <h:outputText value="#{bundle.ViewSalesOrderEntityLabel_internalStatus}"/>
                <h:outputText value="#{salesOrderEntityController.selected.internalStatus}" title="#{bundle.ViewSalesOrderEntityTitle_internalStatus}"/>

                <h:outputText value="#{bundle.ViewSalesOrderEntityLabel_status}"/>
                <p:menuButton value="#{salesOrderEntityController.selected.status}"> 
                    <p:menuitem ajax="false" action="#{salesOrderEntityController.confirmSO}" value="Confirm" rendered="#{salesOrderEntityController.confirmButton()==true}"/>
                    <p:menuitem ajax="false" action="#{salesOrderEntityController.suspendSO}" value="Suspend" rendered="#{salesOrderEntityController.suspendEditButton()==true}"/>
                    <p:menuitem ajax="false" action="#{salesOrderEntityController.resumeSO}" value="Resume" rendered="#{salesOrderEntityController.resumeButton()==true}"/>
                    <p:menuitem ajax="false" action="#{salesOrderEntityController.cancelSO}" value="Cancel" rendered="#{salesOrderEntityController.cancelButton()==true}"/>
                    <p:menuitem ajax="false" action="#{salesOrderEntityController.completeSO}" value="Completed" rendered="#{salesOrderEntityController.completedButton()==true}"/>
                </p:menuButton>

                <h:outputText value="#{bundle.ViewSalesOrderEntityLabel_backorder}"/>

                <p:commandButton update="@form" id="backorderCreateButton" value="Create" action="#{backorderEntityController.create}" rendered="#{salesOrderEntityController.selected.backorder==null}"/>
                <p:commandButton oncomplete="backorderDialog.show()" id="backorderViewButton" value="View" rendered="#{salesOrderEntityController.selected.backorder!=null}">
                    <f:setPropertyActionListener target="#{backorderEntityController.current}" value="#{salesOrderEntityController.selected.backorder}"/>
                </p:commandButton>
                <h:outputText value="#{bundle.ViewSalesOrderEntityLabel_pickList}"/>
                <h:outputText value="#{salesOrderEntityController.selected.pickList}" title="#{bundle.ViewSalesOrderEntityTitle_pickList}"/>

                <h:outputText value="#{bundle.ViewSalesOrderEntityLabel_purchaseOrder}"/>
                <h:outputText value="#{salesOrderEntityController.selected.purchaseOrder}" title="#{bundle.ViewSalesOrderEntityTitle_purchaseOrder}"/>

                <h:outputText value="#{bundle.ViewPurchaseOrderEntityLabel_salesQuotation}"/>
                <h:outputText value="#{purchaseOrderEntityController.selected.salesQuotation}" title="#{bundle.ViewPurchaseOrderEntityTitle_salesQuotation}"/>

            </h:panelGrid>
        </p:panel>
        <p:dialog id="backorderDialogId" header="Backorder for sales order ##{salesOrderEntityController.selected.id}" widgetVar="backorderDialog" width="600" height="500" modal="true">     
            <p:panel id="backorderDialogPanel">
                <h:panelGrid id="backorderDialogPanelGrid" columns="2">
                    <h:outputLabel for="backorderID" value="Back Order ##{salesOrderEntityController.selected.backorder.id}" />
                    <h:outputLabel value=""/>  

                    <h:outputLabel rendered="#{backorderEntityController.backorderEdit==false}" value="Required Lead Time: " />
                    <h:outputLabel rendered="#{backorderEntityController.backorderEdit==false}" for="requiredLeadTimeID" value="#{salesOrderEntityController.selected.backorder.requiredLeadTime}">
                        <!--                                <f:convertDateTime pattern="EEE, MMM d, yyyy"/>-->
                    </h:outputLabel>

                    <h:outputLabel rendered="#{backorderEntityController.backorderEdit==false}" value="Confirmed Lead Time: "/>
                    <h:outputLabel rendered="#{backorderEntityController.backorderEdit==false}" for="confirmedLeadTimeID" value="#{salesOrderEntityController.selected.backorder.confirmedLeadTime}">
                        <!--                                <f:convertDateTime pattern="MM/dd/yyyy"/>-->
                    </h:outputLabel>

                    <h:outputLabel rendered="#{backorderEntityController.backorderEdit==true}" value="Required Lead Time:"/>
                    <p:calendar rendered="#{backorderEntityController.backorderEdit==true}"
                                value="#{backorderEntityController.selected.requiredLeadTime}"
                                onSelectUpdate="backorderDialogPanel"
                                showOn="button">
                    </p:calendar>

                    <h:outputLabel rendered="#{backorderEntityController.backorderEdit==true}" value="Confirmed Lead Time:"/>
                    <p:calendar rendered="#{backorderEntityController.backorderEdit==true}"
                                value="#{backorderEntityController.selected.confirmedLeadTime}"
                                onSelectUpdate="backorderDialogPanel"
                                showOn="button">
                    </p:calendar>

                    <p:commandButton value="Edit"
                                     update="backorderDialogPanel"
                                     action="#{backorderEntityController.editBackorder}"
                                     rendered="#{backorderEntityController.backorderEdit==false}"/>
                    <p:commandButton value="Save"
                                     update="backorderDialogPanel"
                                     action="#{backorderEntityController.editBackorder}"
                                     rendered="#{backorderEntityController.backorderEdit==true}"/>
                </h:panelGrid>
            </p:panel>

            <p:panel id="mainPanel">
                <h:panelGrid columns="2">
                    <p:dataTable  rendered="#{backorderEntityController.pqpListSize gt 0 and backorderEntityController.inEdit==false}" value="#{backorderEntityController.selected.productQuantityPriceList}" var="pqp" >
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="Product"/>
                            </f:facet>
                            <h:outputText value="#{pqp.product.productName}"/>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="Quantity"/>
                            </f:facet>
                            <h:outputText value="#{pqp.quantity}"/>
                        </p:column>
                    </p:dataTable>

                    <p:dataTable  rendered="#{backorderEntityController.pqpListSize eq 0 and backorderEntityController.inEdit==false}" value="#{purchaseOrderEntityController.selected.productQuantityPrice}" var="pqp" >
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="Product"/>
                            </f:facet>
                            <h:outputText value="#{pqp.product.productName}"/>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="Quantity"/>
                            </f:facet>
                            <h:outputText value="#{pqp.quantity}"/>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="Price"/>
                            </f:facet>
                            <h:outputText value="#{pqp.price}"/>
                        </p:column>
                    </p:dataTable>
                    &nbsp;
                    <p:commandButton rendered="#{backorderEntityController.inEdit==false}" value="Edit PQP" action="#{backorderEntityController.editToggle}" update="mainPanel"/>

                    <p:dataTable  rendered="#{backorderEntityController.pqpListSize gt 0 and backorderEntityController.inEdit==true}" value="#{backorderEntityController.selected.productQuantityPriceList}" var="pqp" >
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="Product"/>
                            </f:facet>
                            <h:outputText value="#{pqp.product.productName}"/>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="Quantity"/>
                            </f:facet>
                            <h:inputText value="#{pqp.quantity}"/>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="Price"/>
                            </f:facet>
                            <h:inputText value="#{pqp.price}"/>
                        </p:column>
                    </p:dataTable>
                    <p:commandButton rendered="#{backorderEntityController.inEdit==true and backorderEntityController.pqpListSize gt 0}" value="Save" action="#{backorderEntityController.editPqpList}" update="mainPanel"/>

                    <h:panelGrid border="0" rendered="#{backorderEntityController.inEdit==true and backorderEntityController.pqpListSize eq 0}" columns="3">
                        <h:outputLabel value="Product:" style="font-weight:bold"/>
                        <h:outputLabel value="Quantity (Number of Case(s)):" style="font-weight:bold"/>
                        <h:outputLabel value="Price (S$):" style="font-weight:bold"/>


                        <h:outputLabel value="Premium Power Bar (Redcurrant Fruits)" for="product" />
                        <p:inputText id="quantityPqp4" value="#{backorderEntityController.pqp4Quantity}" title="PQP4" />
                        <p:inputText id="pricePqp4" value="#{backorderEntityController.pqp4Price}" />


                        <h:outputLabel value="Classic Nutri Bar (Fruits)" for="product" />
                        <p:inputText id="quantityPqp2" value="#{backorderEntityController.pqp2Quantity}" title="PQP2" />
                        <p:inputText id="pricePqp2" value="#{backorderEntityController.pqp2Price}" />

                        <h:outputLabel value="Classic Nutri Bar (Nuts)" for="product" />
                        <p:inputText id="quantityPqp1" value="#{backorderEntityController.pqp1Quantity}" title="PQP1" />
                        <p:inputText id="pricePqp1" value="#{backorderEntityController.pqp1Price}" />

                        <h:outputLabel value="Premium Power Bar (Chocolate Nuts)" for="product" />
                        <p:inputText id="quantityPqp3" value="#{backorderEntityController.pqp3Quantity}" title="PQP3" />
                        <p:inputText id="pricePqp3" value="#{backorderEntityController.pqp3Price}" />

                        <p:commandButton rendered="#{backorderEntityController.inEdit==true and backorderEntityController.pqpListSize eq 0}" value="Save" action="#{backorderEntityController.savePqpList}" update="mainPanel"/>
                    </h:panelGrid>
                </h:panelGrid>
            </p:panel>

        </p:dialog>
    </ui:composition>

</html>
